#pragma once

#include "IXMenuEx.h"
#include "XBaseObjImpl.h"
#include "IXWindow.h"
#include "EventHandler.h"

#include <IXLayout.h>
#include <IXConfigNode.h>

#include <vector>

class CXMenuExImpl : public CXBaseObjImpl<IXMenuEx>, public CXEventHandler<CXMenuExImpl>
{
    typedef CXBaseObjImpl<IXMenuEx> superclass;
    BEGIN_DEF_SKIN_CLASS(CXMenuExImpl, superclass, gs_strGuidXSkin)
        IMP_BASIC_INTF(IXMenuEx,  0)
        END_DEF_SKIN_CLASS();

public:
    // 
    CXMenuExImpl();
    virtual ~CXMenuExImpl();

public:
    // IXMenuEx
    virtual HRESULT STDMETHODCALLTYPE   CreateMenuItem(IN OUT IXMenuItem** ppItem, IN LPCTSTR szItemId);
    virtual HRESULT STDMETHODCALLTYPE   TrackPopupMenu(IN LONG x, IN LONG y, IN XWND xWnd, OUT BSTR* pbstrCmdId);

protected:
    // CXBaseObjImpl
    virtual void STDMETHODCALLTYPE   OnFinalRelease();

protected:
    // Event
    void    OnItemClicked(IXControl* pItem, LPARAM lParam);
    void    OnMenuFrameQueryClose(IXControl* pItem, LPARAM lParam);

protected:
    void    DestroyItems();
    HRESULT NeedMenuFrame();
    void    AdjustMenuFrame();

protected:

    typedef std::vector<IXMenuItem*>  MenuItemVector;
    MenuItemVector  m_vctMenuItem;

    XBSTR       m_strSelectedItemId;
    IXWindow*   m_pMenuFrame;
    BOOL        m_bValid;
};
